﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace WooCoo.Web.MVC
{
    public class AuthController:Controller
    {
         /// <summary>
        /// 方法执行前，如果没有登录就调整到Passport登录页面，没有权限就抛出信息
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var allowAnonymousAttribute = filterContext.ActionDescriptor.GetCustomAttributes(false).OfType<AllowAnonymousAttribute>();
            if (allowAnonymousAttribute.Count() > 0)
                return;

            base.OnActionExecuting(filterContext);

            if (!Request.IsAuthenticated)
            {
                filterContext.Result = new RedirectResult("/Login/Index");
                return;
            }
        }
    }
}
